package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ShoppingCartController
 * Package: com.sky.controller.user
 * Description:
 *
 * @Author JJQ
 * @create 2024/5/18 0018 15:11
 * @Version 1.0
 */
@RestController
@RequestMapping("/user/cart")
@Slf4j
@Api(tags = "c端购物车")
public class ShoppingCartController {

    @Autowired
    ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("新增购物车商品")
    public Result add(ShoppingCartDTO shoppingCartDTO) {
        this.shoppingCartService.add(shoppingCartDTO);
        return Result.success("添加成功");
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list () {
        return Result.success(shoppingCartService.getList());
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除购物车")
    public Result clear () {
        shoppingCartService.delete();
        return Result.success("清除成功");
    }
}
